//
//  ListenToSingleModeViewController.m
//  QXDLLOrdersModule
//
//  Created by DL on 17/1/4.
//  Copyright © 2017年 DLL. All rights reserved.
//

#import "ListenToSingleModeViewController.h"
#import "InstructionView.h"
#import "DLLApiManager.h"
#import "TimeSelectorVC.h"
#import <QXDriverConfiguration/QXDriverConfiguration.h>
#import "IflyMSCManager.h"
#import "iflyMSC/iflyMSC.h"
#import <QXDataManager/QXDataManager.h>
#import <QXYueYueModels/QXYYUserDriverModel.h>
#import "AppManager.h"
#import "AppInfoModel.h"
#import "AppManagerHeader.h"
#import "listenToSingleTabCell.h"
#import "ColorManager.h"
#import "NotificationNameManager.h"
#import "AppManager.h"
#import "AppInfoModel.h"
#import "AppManagerHeader.h"


NSString * const LisenToSingleModeAppointTime_Begin = @"LisenToSingleModeAppointTime_Begin";
NSString * const LisenToSingleModeAppointTime_End = @"LisenToSingleModeAppointTime_End";
/// 听单模式的 type
NSString *ListenSingleType = @"ListenSingleType";


#define TOPMOBILEPOINTX  self.selectTypeView.frame.size.width/3

@interface ListenToSingleModeViewController ()<TimeSelectorVCDelegate , UICollectionViewDelegate , UICollectionViewDataSource , UICollectionViewDelegateFlowLayout>
/// 弹出视图
@property (weak, nonatomic) IBOutlet UIView *popView;
/// 选择实时预约模式的视图
@property (weak, nonatomic) IBOutlet UIView *selectTypeView;
/// 实时按钮
@property (weak, nonatomic) IBOutlet UIButton *realTimeButton;
/// 预约按钮
@property (weak, nonatomic) IBOutlet UIButton *reservationButton;
/// 全部按钮
@property (weak, nonatomic) IBOutlet UIButton *allButton;
/// 顶部移动按钮
@property (weak, nonatomic) IBOutlet UIButton *topMobileButton;
/// 移动约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topMobileLayoutConstraint;


/// 选择时间背景图
@property (weak, nonatomic) IBOutlet UIView *selectTimeBackView;

/// 选择现在时间按钮
@property (weak, nonatomic) IBOutlet UIView *nowTimeButtonBackView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *nowTimeClearButtonWidth;
@property (weak, nonatomic) IBOutlet UIButton *nowTimeButton;

/// 到任意时间按钮
@property (weak, nonatomic) IBOutlet UIView *arbitraryTimeButtonBackView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *arbitraryTimeButtonWidth;

@property (weak, nonatomic) IBOutlet UIButton *arbitraryTimeButton;
/// 完成按钮
@property (weak, nonatomic) IBOutlet UIButton *completeButton;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *popViewMarginToLeft;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *popViewMarginToTop;


/**
 听单模式 1：全部，2：实时 3：预约
 */
@property(nonatomic , assign) NSInteger remindType;

/**
 设置开始时间
 */
@property(nonatomic , assign) NSTimeInterval beginTimeStamp;
@property(nonatomic , strong) NSMutableArray *beginDayArray; // 开始的 日 数组,用于展示 @[@"20" , @"21" , @"22"]
@property(nonatomic , strong) NSMutableArray *beginFirstHourTimeArray; // 开始第一天的小时数组 @[@"02" , @"03" , ... , @"23"] , 用于展示
@property(nonatomic , strong) NSMutableArray *beginDateTimeArray; // 存储开始 yyyy-MM-dd 格式日期的数组 , 用于时间转化时间戳的拼接

@property(nonatomic , strong) NSMutableArray *hourTimeArray; // 第二天(包含第二天)以后的小时数组 @[@"00" , @"01" , ... , @"23"] , 用于展示
@property(nonatomic , copy) NSString *beginDateTimeString; // 开始yyyy-MM-dd时间
@property(nonatomic , copy) NSString *beginHourTimeString; // 开始HH时间

/**
 设置结束时间
 */
@property(nonatomic , assign) NSTimeInterval endTimeStamp;
@property(nonatomic , strong) NSMutableArray *endDayArray;  // 结束的 日 数组,用于展示 @[@"20" , @"21" , @"22"]
@property(nonatomic , strong) NSMutableArray *endFirstHourTimeArray; // 结束第一天的小时数组 @[@"02" , @"03" , ... , @"23"] , 用于展示
@property(nonatomic , strong) NSMutableArray *endDateTimeArray; // 存储结束 yyyy-MM-dd 格式日期的数组 , 用于时间转化时间戳的拼接
@property(nonatomic , copy) NSString *endDateTimeString; // 结束yyyy-MM-dd时间
@property(nonatomic , copy) NSString *endHourTimeString; // 结束HH时间


/**
 时间选择器的类型
 1: 开始时间 , 2: 结束时间
 */
@property(nonatomic , assign) NSInteger timeSelectorType;



/**
 选择的日行数
 */
@property(nonatomic , assign) NSInteger selectDayRow;

/**
 选择的小时行数
 */
@property(nonatomic , assign) NSInteger selectHourRow;


/**
 背景视图
 */
@property (weak, nonatomic) IBOutlet InstructionView *backImageView;

@property (weak, nonatomic) IBOutlet UIImageView *backGroundImageView;

/// 听单选项卡视图
@property (weak, nonatomic) IBOutlet UIView *listenToSingleTabView;
/// 听单模式选项卡
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
/// 听单模式选项卡选中移动的 view
@property (weak, nonatomic) IBOutlet UIView *selectedMovingView;
/// 左移动坐标,与选中的选项卡的 x 坐标保持一致
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectedMovingViewX;
/// 听单模式选项卡移动视图的高度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectedMovingViewHeight;
/// 听单模式选项卡移动视图的宽度
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectedMovingViewWidth;
/// 听单模式选项卡移动视图的标题
@property (weak, nonatomic) IBOutlet UILabel *selectedMovingTitleLabel;




/// 听单模式数据源
@property (nonatomic ,strong) NSArray *listenToSingleModeDataSource;


@end

static ListenToSingleModeViewController *listenToSingleModeViewController = nil;

@implementation ListenToSingleModeViewController

- (NSMutableArray *)beginDayArray {
    if (!_beginDayArray) {
        self.beginDayArray = [NSMutableArray array];
    }
    return _beginDayArray;
}

- (NSMutableArray *)beginFirstHourTimeArray {
    if (!_beginFirstHourTimeArray) {
        self.beginFirstHourTimeArray = [NSMutableArray array];
    }
    return _beginFirstHourTimeArray;
}

- (NSMutableArray *)beginDateTimeArray {
    if (!_beginDateTimeArray) {
        self.beginDateTimeArray = [NSMutableArray array];
    }
    return _beginDateTimeArray;
}



- (NSMutableArray *)hourTimeArray {
    if (!_hourTimeArray) {
        self.hourTimeArray = [NSMutableArray array];
    }
    return _hourTimeArray;
}

- (NSMutableArray *)endDayArray {
    if (!_endDayArray) {
        self.endDayArray = [NSMutableArray array];
    }
    return _endDayArray;
}

- (NSMutableArray *)endFirstHourTimeArray {
    if (!_endFirstHourTimeArray) {
        self.endFirstHourTimeArray = [NSMutableArray array];
    }
    return _endFirstHourTimeArray;
}

- (NSMutableArray *)endDateTimeArray {
    
    if (!_endDateTimeArray) {
        self.endDateTimeArray = [NSMutableArray array];
    }
    return _endDateTimeArray;
}


+ (instancetype)shareSelf {
    return [[UIStoryboard storyboardWithName:@"Orders" bundle:nil] instantiateViewControllerWithIdentifier:@"ListenToSingleModeViewController"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.alpha = 0.0;
    listenToSingleModeViewController = self;
    
    [self registerNotification];
    
    [self configureDefaultAttributes];
    
    [self configureFillet];
}




- (void)refreshPopViewUI {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
        self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
    });
}


/**
 配置圆角
 */
- (void)configureFillet {
    
    // 弹出试图
    self.popView.layer.cornerRadius = 5.0;
    self.popView.layer.masksToBounds = YES;
    self.popView.backgroundColor = [UIColor clearColor];
    
    // 完成按钮
    self.completeButton.layer.cornerRadius = 30;
    self.completeButton.layer.masksToBounds = YES;
    
    // 听单模式背景视图
    self.selectTypeView.layer.cornerRadius = self.selectTypeView.frame.size.height / 2.0;
    self.selectTypeView.layer.masksToBounds = YES;
    
    // 选择听单模式的按钮
    self.topMobileButton.layer.cornerRadius = self.topMobileButton.frame.size.height / 2.0;
    self.topMobileButton.layer.masksToBounds = YES;
    
    // 开始时间
    self.nowTimeButtonBackView.layer.cornerRadius = 5.0;
    self.nowTimeButtonBackView.layer.masksToBounds = YES;
    
    // 任意时间
    self.arbitraryTimeButtonBackView.layer.cornerRadius = 5.0;
    self.arbitraryTimeButtonBackView.layer.masksToBounds = YES;

}

- (void)configureDefaultAttributes {
    
    // 默认选中的是全部订单
    self.remindType = 1;
    
    self.backGroundImageView.image = [QXDriverConfiguration imageWithName:@"bg"];

//    self.listenToSingleTabView.hidden = YES;
    self.collectionView.backgroundColor = [ColorManager getSelectedCorlorOfListenToSingleBack];
    self.selectedMovingView.backgroundColor = [ColorManager getSelectedColorOfListenToSingleTab];

    [self refreshListenSingleType];
}



#pragma 刷新订单模式,如果为专车快车,有包车,如果为货的,搬家,骑手,出租车,没有包车
- (void)refreshListenSingleType {

    QXYYUserDriverModel *driverModel = [QXYYUserDriverModel QXYY_unarchiveObject];
    if (driverModel.type == DriverTypeExpressCar || driverModel.type == DriverTypeSpecialCar) { // 如果是快车或者专车
        AppManager *appManager = [AppManager shareManager];
        AppInfoModel *appInfoModel = [appManager getAppInfo];
        if (appInfoModel.AppDriverOrgan == AppDriverOrganNameOfMiaoSheng || appInfoModel.AppDriverOrgan == AppDriverOrganNameOfWeiWeiYunLi || appInfoModel.AppDriverOrgan == AppDriverOrganNameOfWeiBa) {
            
            self.listenToSingleModeDataSource = @[@"实时" , @"预约" , @"全部"];
        }else {
            
            self.listenToSingleModeDataSource = @[@"实时" , @"预约" , @"包车" , @"全部"];
        }
        
    }else {
        
        self.listenToSingleModeDataSource = @[@"实时" , @"预约" , @"全部"];
    }
    
    NSInteger listenSingleType = [[QXDataManager getValueForKey:[NSString stringWithFormat:@"%@_%@" ,ListenSingleType , driverModel.uuid]] integerValue];
    CGSize cellSize = [self cellSize];
    if (listenSingleType >= 0 && listenSingleType) {
        
        
        self.selectedMovingViewWidth.constant = cellSize.width;
        self.selectedMovingViewHeight.constant = cellSize.height;
        self.selectedMovingViewX.constant = listenSingleType * (cellSize.width + 5) + 5;
        if (listenSingleType < self.listenToSingleModeDataSource.count) {
            
            self.selectedMovingTitleLabel.text = self.listenToSingleModeDataSource[listenSingleType];
            [self selectedListentModeWithRow:listenSingleType];
        }else if (listenSingleType >= self.listenToSingleModeDataSource.count) { // 防止不同账号切换引起越界
            
            self.selectedMovingTitleLabel.text = self.listenToSingleModeDataSource[self.listenToSingleModeDataSource.count - 1];
            [self selectedListentModeWithRow:self.listenToSingleModeDataSource.count - 1];
            [QXDataManager saveValue:@(self.listenToSingleModeDataSource.count - 1) forKey:ListenSingleType]; // 更新数据
        }
        
    }else {
        

        self.selectedMovingViewWidth.constant = cellSize.width;
        self.selectedMovingViewHeight.constant = cellSize.height;
        self.selectedMovingViewX.constant = (self.listenToSingleModeDataSource.count - 1) * (cellSize.width + 5) + 5;
        self.selectedMovingTitleLabel.text = self.listenToSingleModeDataSource.lastObject;
        [self selectedListentModeWithRow:self.listenToSingleModeDataSource.count - 1];
        [QXDataManager saveValue:@(self.listenToSingleModeDataSource.count - 1) forKey:ListenSingleType]; // 更新数据
    }
    
    self.selectedMovingView.layer.cornerRadius = cellSize.height / 2.0;
    self.selectedMovingView.layer.masksToBounds = YES;
    self.selectedMovingTitleLabel.font = [UIFont systemFontOfSize:16];
    self.selectedMovingTitleLabel.textColor = [ColorManager getFontColorOfListenToSingleTab];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self.collectionView reloadData];
    });
}


/**
 配置听单模式弹出框的UI
 */
- (void)configureLisenToSingleModeVCUI {
    
    NSTimeInterval nowTimeStamp = [self getOneDayTimeStampWithOneDayFromNow:0 delayHourTime:0];
    

    NSTimeInterval beginStamp = [[QXDataManager getValueForKey:LisenToSingleModeAppointTime_Begin] doubleValue];
    if (nowTimeStamp > beginStamp) { // 如果当前时间大于预约时间置为-1.0
        

        [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_Begin];
    }

    beginStamp = [[QXDataManager getValueForKey:LisenToSingleModeAppointTime_Begin] doubleValue];
    if (beginStamp <= 0) {
        
        self.nowTimeClearButtonWidth.constant = 0.0;
        self.nowTimeButtonBackView.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:47 / 255.0 blue:84 / 255.0 alpha:1.0];
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self.nowTimeButton setTitle:@"从现在" forState:(UIControlStateNormal)];
            [self.nowTimeButton setTitleColor:[UIColor colorWithRed:118 / 255.0 green:140 / 255.0 blue:226 / 255.0 alpha:1.0] forState:(UIControlStateNormal)];
        });
    }else {
        
        self.nowTimeClearButtonWidth.constant = 30.0;
        self.nowTimeButtonBackView.backgroundColor = [UIColor colorWithRed:62 / 255.0 green:136 / 255.0 blue:245 / 255.0 alpha:1.0];
        NSString *timeString = [self getOneDayWithFormatter:@"dd日HH时" timeStamp:beginStamp / 1000];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.self.nowTimeButton setTitle:timeString forState:(UIControlStateNormal)];
            [self.self.nowTimeButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            [self.view layoutIfNeeded];
        });
    }
    self.beginTimeStamp = beginStamp;
    
    

    NSTimeInterval endTimeStamp = [[QXDataManager getValueForKey:LisenToSingleModeAppointTime_End] doubleValue];
    if (nowTimeStamp > endTimeStamp) { // 如果当前时间大于预约时间置为-1.0
        

        [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_End];
    }

    endTimeStamp = [[QXDataManager getValueForKey:LisenToSingleModeAppointTime_End] doubleValue];
    if (endTimeStamp <= 0) {
        
        self.arbitraryTimeButtonWidth.constant = 0.0;
        self.arbitraryTimeButtonBackView.backgroundColor = [UIColor colorWithRed:37 / 255.0 green:47 / 255.0 blue:84 / 255.0 alpha:1.0];
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self.arbitraryTimeButton setTitle:@"到任意时间" forState:(UIControlStateNormal)];
            [self.arbitraryTimeButton setTitleColor:[UIColor colorWithRed:118 / 255.0 green:140 / 255.0 blue:226 / 255.0 alpha:1.0] forState:(UIControlStateNormal)];
        });
    }else {
        
        self.arbitraryTimeButtonWidth.constant = 30.0;
        self.arbitraryTimeButtonBackView.backgroundColor = [UIColor colorWithRed:62 / 255.0 green:136 / 255.0 blue:245 / 255.0 alpha:1.0];
        NSString *timeString = [self getOneDayWithFormatter:@"dd日HH时" timeStamp:endTimeStamp / 1000];

        dispatch_async(dispatch_get_main_queue(), ^{
            [self.arbitraryTimeButton setTitle:timeString forState:(UIControlStateNormal)];
            [self.arbitraryTimeButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            [self.view layoutIfNeeded];
        });
        
    }
    self.endTimeStamp = endTimeStamp;
    
    self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
    self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
}





/**
 根据时间戳,时间格式获取指定类型的时间

 @param formatter 时间格式
 @return 时间戳
 */
- (NSString *)getOneDayWithFormatter:(NSString *)formatter timeStamp:(NSTimeInterval)timeStamp {
    
    NSDate *oneDate = [NSDate dateWithTimeIntervalSince1970:timeStamp];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:formatter];
    NSString *dateString = [dateFormatter stringFromDate:oneDate];
    return dateString;
}



/**
 根据时间字符串,以及相同格式的字符串表达式(yyyy-MM-dd HH:mm:ss:SSS)生成时间戳`

 @param timeString 时间字符串
 @param formatter 与时间字符串格式相同的时间表达式
 @return 返回的时间戳
 */
- (NSTimeInterval)getOneDayTimeStampWithTimeString:(NSString *)timeString formatter:(NSString *)formatter {

    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
    [inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SSS"];
    NSDate *inputDate = [inputFormatter dateFromString:timeString];
    NSTimeInterval timeSp = [inputDate timeIntervalSince1970];
    
    return timeSp;
    
}

#pragma 注册通知
- (void)registerNotification {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOutSuccess:) name:NotificationName_LoginOutSuccess object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess:) name:NotificationName_LoginSuccess object:nil];
}

/// 登出成功
- (void)loginOutSuccess:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:NotificationName_LoginOutSuccess]) {
        
        [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_Begin];
        [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_End];
//        [QXDataManager saveValue:@"0" forKey:ListenSingleType];
    }
}

/// 登陆成功
- (void)loginSuccess:(NSNotification *)aNotification {
    
    if ([aNotification.name isEqualToString:NotificationName_LoginSuccess]) {
        
        [self refreshListenSingleType];
    }
}

#pragma 如果该控制器初始化了那么获取该控制器
+ (ListenToSingleModeViewController *)returnListenToSingleModeViewController {
    
    return listenToSingleModeViewController;
}

#pragma mark -设置听单模式
- (IBAction)setListeningModeAction:(UIButton *)sender {
    switch (sender.tag) {
        case 111: // 实时单
        {
            [self MoveTheAnimation:TOPMOBILEPOINTX*2 integer:2];
            self.selectTimeBackView.alpha = 0.0;
            self.remindType = 2;
        }
            break;
            
        case 222: // 预约单
        {
            [self MoveTheAnimation:TOPMOBILEPOINTX*1 integer:1];
            self.selectTimeBackView.alpha = 1.0;
            self.remindType = 3;
        }
            break;
            
        case 333: // 全部订单
        {
            [self MoveTheAnimation:TOPMOBILEPOINTX*0 integer:0];
            self.selectTimeBackView.alpha = 1.0;
            self.remindType = 1;
        }
            break;
            
        default:
            break;
    }
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.listenToSingleModeDataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    listenToSingleTabCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"listenToSingleTabCellID" forIndexPath:indexPath];
    
    if (self.listenToSingleModeDataSource.count > 0) {
        
        NSString *titleStr = self.listenToSingleModeDataSource[indexPath.row];
        [cell setValuesWithString:titleStr];
    }
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    

    
    return [self cellSize];
}

- (CGSize)cellSize {
    
    CGFloat height = self.collectionView.frame.size.height - 6;
    
    CGFloat width = (([UIScreen mainScreen].bounds.size.width - 90) - (5 * (self.listenToSingleModeDataSource.count - 1)) - 10) / (CGFloat)self.listenToSingleModeDataSource.count;
    
    CGSize size = CGSizeMake(width, height);
    
    return size;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    
    return 5;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    
    return 5;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    
    return UIEdgeInsetsMake(3, 5, 3, 5);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    QXYYUserDriverModel *driverModel = [QXYYUserDriverModel QXYY_unarchiveObject];
    // 设置听单模式
    [self selectedListentModeWithRow:indexPath.row];
    [QXDataManager saveValue:[NSString stringWithFormat:@"%ld" , indexPath.row] forKey:[NSString stringWithFormat:@"%@_%@" ,ListenSingleType , driverModel.uuid]]; // 更新数据
    
    
    // 设置选中动画
    listenToSingleTabCell *cell = (listenToSingleTabCell *)[collectionView cellForItemAtIndexPath:indexPath];
    CGRect rect = [collectionView convertRect:cell.frame toView:self.listenToSingleTabView];
    [UIView animateWithDuration:0.25 delay:0.0 options:(UIViewAnimationOptionCurveLinear) animations:^{
        
        self.selectedMovingViewX.constant = rect.origin.x;
        [self.listenToSingleTabView layoutIfNeeded];

    } completion:^(BOOL finished) {
        
        if (indexPath.row < self.listenToSingleModeDataSource.count) {
            
            self.selectedMovingTitleLabel.text = self.listenToSingleModeDataSource[indexPath.row];
            self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
            self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
        }
        
    }];
    
}

#pragma 设置听单模式
- (void)selectedListentModeWithRow:(NSInteger)row {
    
    NSString *title = self.listenToSingleModeDataSource[row];
        
    if ([title isEqualToString:@"实时"]) {
        
        self.remindType = 2;
        self.selectTimeBackView.hidden = YES;
    }else if ([title isEqualToString:@"预约"]) {
        
        self.remindType = 3;
        self.selectTimeBackView.hidden = NO;
    }else if ([title isEqualToString:@"包车"]) {
        
        self.remindType = 4;
        self.selectTimeBackView.hidden = NO;
    }else if ([title isEqualToString:@"全部"]) {
        
        self.remindType = 1;
        self.selectTimeBackView.hidden = NO;
    }
    
}


#pragma mark -移动动画 
- (void)MoveTheAnimation:(CGFloat)pointX integer:(NSInteger)integer {
    
    // 动画期间不让点击完成按钮 , 动画结束后可以点击
    self.completeButton.userInteractionEnabled = NO;
    
    [UIView animateWithDuration:0.3 delay:0.0 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
        
        self.topMobileLayoutConstraint.constant = -pointX;
        [self.popView layoutIfNeeded];
    } completion:^(BOOL finished) {
    
        switch (integer) {
            case 0: {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [self.topMobileButton setTitle:@"全部" forState:(UIControlStateNormal)];
                });
                break;
            }
            case 1: {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.topMobileButton setTitle:@"预约" forState:(UIControlStateNormal)];
                });
                break;
            }
            case 2: {
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.topMobileButton setTitle:@"实时" forState:(UIControlStateNormal)];
                });
                break;
            }
            default: {
                break;
            }
        }

        self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
        self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
        self.completeButton.userInteractionEnabled = YES;
    }];
}


#pragma mark -选择预约时间
- (IBAction)SelectTheTimeAction:(UIButton *)sender {
    
    TimeSelectorVC *timeSelectorVC = [TimeSelectorVC initTimeSelectorVC];
    timeSelectorVC.delegate = self;
    [self clearArray];
    timeSelectorVC.confirmActionBlock = ^() {
        
        if (self.timeSelectorType == 1) {
            
            NSString *timeString = [self getOneDayWithFormatter:@"dd日HH时" timeStamp:self.beginTimeStamp / 1000];
            [self.nowTimeButton setTitle:timeString forState:(UIControlStateNormal)];
            self.nowTimeClearButtonWidth.constant = 30.0;
            self.nowTimeButtonBackView.backgroundColor = [UIColor colorWithRed:62 / 255.0 green:136 / 255.0 blue:245 / 255.0 alpha:1.0];
            [self.nowTimeButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];

            [QXDataManager saveValue:[NSString stringWithFormat:@"%.f" , self.beginTimeStamp] forKey:LisenToSingleModeAppointTime_Begin];

            if (self.beginTimeStamp >= self.endTimeStamp) {
                
                [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_End];
                [self configureLisenToSingleModeVCUI];
            }
        }else {
            
            NSString *timeString = [self getOneDayWithFormatter:@"dd日HH时" timeStamp:self.endTimeStamp / 1000];
            [self.arbitraryTimeButton setTitle:timeString forState:(UIControlStateNormal)];
            self.arbitraryTimeButtonWidth.constant = 30.0;
            self.arbitraryTimeButtonBackView.backgroundColor = [UIColor colorWithRed:62 / 255.0 green:136 / 255.0 blue:245 / 255.0 alpha:1.0];
            [self.arbitraryTimeButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            [QXDataManager saveValue:[NSString stringWithFormat:@"%.f" , self.endTimeStamp] forKey:LisenToSingleModeAppointTime_End];
        }
    };
    
    self.selectHourRow = 0;
    self.selectDayRow = 0;
    switch (sender.tag) {
        case 123:
        {
            NSString *nowDateString = [self getOneDayWithFormatter:@"yyyyMMdd" timeStamp:[self getOneDayTimeStampWithOneDayFromNow:0 delayHourTime:0] / 1000]; // 当前时间
            NSString *beginDateString = [self getOneDayWithFormatter:@"yyyyMMdd" timeStamp:[self getOneDayTimeStampWithOneDayFromNow:0 delayHourTime:1] / 1000]; // 延迟一小时后的时间
            NSInteger beginDay = -1;
            NSInteger endDay = -1;
            if ([beginDateString isEqualToString:nowDateString]) {
                
                beginDay = 0;
                endDay = 3;
            }else {
                
                beginDay = 1;
                endDay = 3;
            }
            [self getTimeArrayWithDelayHourTime:1 timeType:1 beginDay:beginDay endDay:endDay];
            self.timeSelectorType = 1;
            self.beginDateTimeString = self.beginDateTimeArray.firstObject;
            self.beginHourTimeString = self.beginFirstHourTimeArray.firstObject;
            NSString *timeString = [NSString stringWithFormat:@"%@ %@:00:00:000" , self.beginDateTimeString , self.beginHourTimeString]; // yyyy-MM-dd HH:mm:ss:SSS
            NSTimeInterval timeStamp = [self getOneDayTimeStampWithTimeString:timeString formatter:@"yyyy-MM-dd HH:mm:ss:SSS"] * 1000; // 转化到毫秒
            if (self.beginTimeStamp <= 0) {
                
                self.beginTimeStamp = timeStamp;
            }
            
            timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:0 row:0];
            
            if (self.beginTimeStamp > 0) {
                
                NSString *dayString = [self getOneDayWithFormatter:@"dd" timeStamp:self.beginTimeStamp / 1000];
                NSString *hourString = [self getOneDayWithFormatter:@"HH" timeStamp:self.beginTimeStamp / 1000];
                
                NSInteger dayNumber = 0;
                NSInteger hourNumber = 0;
                
                for (NSInteger j = 0; j < self.beginDayArray.count; j ++) {
                    
                    NSString *dayStringTmp = self.beginDayArray[j];
                    if ([dayString isEqualToString:dayStringTmp]) {
                        
                        dayNumber = j;
                        break;
                    }
                }
                
                if (dayNumber == 0) {
                    
                    for (NSInteger j = 0; j < self.beginFirstHourTimeArray.count; j ++) {
                        
                        NSString *hourStringTmp = self.beginFirstHourTimeArray[j];
                        if ([hourString isEqualToString:hourStringTmp]) {
                            
                            hourNumber = j;
                            break;
                        }
                    }
                }else {
                    
                    for (NSInteger j = 0; j < self.hourTimeArray.count; j ++) {
                        
                        NSString *hourStringTmp = self.hourTimeArray[j];
                        if ([hourString isEqualToString:hourStringTmp]) {
                            
                            hourNumber = j;
                            break;
                        }
                    }
                }

                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [timeSelectorVC.pickView selectRow:dayNumber inComponent:0 animated:NO];
                    [timeSelectorVC.pickView selectRow:hourNumber inComponent:2 animated:NO];
                    timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:0 row:dayNumber];
                    [timeSelectorVC.delegate timeSelectorVC:timeSelectorVC pickView:timeSelectorVC.pickView didSelectRow:dayNumber inComponent:0];
                    [timeSelectorVC.delegate timeSelectorVC:timeSelectorVC pickView:timeSelectorVC.pickView didSelectRow:hourNumber inComponent:2];
                    [timeSelectorVC.pickView reloadAllComponents];
                    
                });

            }
        }
            break;
            
        case 456:
        {
            
            // 计算时间差
            NSInteger beginDay = -1;
            NSInteger endDay = -1;
            if (self.beginTimeStamp > 0) { // 如果选择了开始时间
                
                NSTimeInterval nowTimeStamp = [self getOneDayTimeStampWithOneDayFromNow:0 delayHourTime:0];
                NSString *nowTimeString = [self getOneDayWithFormatter:@"yyyy-MM-dd" timeStamp:nowTimeStamp / 1000];
                nowTimeString = [NSString stringWithFormat:@"%@ 00:00:00:000" , nowTimeString];
                nowTimeStamp = [self getOneDayTimeStampWithTimeString:nowTimeString formatter:@"yyyy-MM-dd HH:ss:mm"];
                
                NSTimeInterval beginTimeStamp = self.beginTimeStamp + 1 * 60 * 60;
                NSString *beginTimeString = [self getOneDayWithFormatter:@"yyyy-MM-dd" timeStamp:beginTimeStamp / 1000];
                beginTimeString = [NSString stringWithFormat:@"%@ 00:00:00:000" , beginTimeString];
                beginTimeStamp = [self getOneDayTimeStampWithTimeString:beginTimeString formatter:@"yyyy-MM-dd HH:ss:mm"];
                NSTimeInterval value = beginTimeStamp - nowTimeStamp;
                NSInteger day = (NSInteger)value / (24 * 3600);
                beginDay = day;
                endDay = 3;
                [self getTimeArrayWithDelayHourTime:2 timeType:2 beginDay:beginDay endDay:endDay];
            }else {
                
                beginDay = 0;
                endDay = 3;
                [self getTimeArrayWithDelayHourTime:1 timeType:2 beginDay:beginDay endDay:endDay];
            }
            
            self.timeSelectorType = 2;
            self.endDateTimeString = self.endDateTimeArray.firstObject;
            self.endHourTimeString = self.endFirstHourTimeArray.firstObject;
            NSString *timeString = [NSString stringWithFormat:@"%@ %@:00:00:000" , self.endDateTimeString , self.endHourTimeString]; // yyyy-MM-dd HH:mm:ss:SSS
            NSTimeInterval timeStamp = [self getOneDayTimeStampWithTimeString:timeString formatter:@"yyyy-MM-dd HH:mm:ss:SSS"] * 1000; // 转化到毫秒
            if (self.endTimeStamp <= 0) {
                
                self.endTimeStamp = timeStamp;
            }
            
            timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:0 row:0];
            
            if (self.endTimeStamp > 0) {
                
                NSString *dayString = [self getOneDayWithFormatter:@"dd" timeStamp:self.endTimeStamp / 1000];
                NSString *hourString = [self getOneDayWithFormatter:@"HH" timeStamp:self.endTimeStamp / 1000];
                
                NSInteger dayNumber = 0;
                NSInteger hourNumber = 0;
                
                for (NSInteger j = 0; j < self.endDayArray.count; j ++) {
                    
                    NSString *dayStringTmp = self.endDayArray[j];
                    if ([dayString isEqualToString:dayStringTmp]) {
                        
                        dayNumber = j;
                        break;
                    }
                }
                
                if (dayNumber == 0) {
                    
                    for (NSInteger j = 0; j < self.endFirstHourTimeArray.count; j ++) {
                        
                        NSString *hourStringTmp = self.endFirstHourTimeArray[j];
                        if ([hourString isEqualToString:hourStringTmp]) {
                            
                            hourNumber = j;
                            break;
                        }
                    }
                }else {
                    
                    for (NSInteger j = 0; j < self.hourTimeArray.count; j ++) {
                        
                        NSString *hourStringTmp = self.hourTimeArray[j];
                        if ([hourString isEqualToString:hourStringTmp]) {
                            
                            hourNumber = j;
                            break;
                        }
                    }
                }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [timeSelectorVC.pickView selectRow:dayNumber inComponent:0 animated:NO];
                    [timeSelectorVC.pickView selectRow:hourNumber inComponent:2 animated:NO];
                    [timeSelectorVC.delegate timeSelectorVC:timeSelectorVC pickView:timeSelectorVC.pickView didSelectRow:dayNumber inComponent:0];
                    [timeSelectorVC.delegate timeSelectorVC:timeSelectorVC pickView:timeSelectorVC.pickView didSelectRow:hourNumber inComponent:2];
                    timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:0 row:dayNumber];
                    [timeSelectorVC.pickView reloadAllComponents];
                    
                });
                
            }
        }
            break;
            
        default:
            break;
    }
    
    [timeSelectorVC show];
    self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
    self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
}

- (NSArray *)getDatasourceWithTimeType:(NSInteger)timeType compont:(NSInteger)compont row:(NSInteger)row {
    
    NSMutableArray *dateArray = [NSMutableArray array];
    if (timeType == 1) {
        
        if (compont == 0) {
            
            if (row == 0) {
                
                [dateArray addObject:self.beginDayArray];
                [dateArray addObject:@[@"日"]];
                [dateArray addObject:self.beginFirstHourTimeArray];
                [dateArray addObject:@[@"时"]];
                
            }else {
                
                [dateArray addObject:self.beginDayArray];
                [dateArray addObject:@[@"日"]];
                [dateArray addObject:self.hourTimeArray];
                [dateArray addObject:@[@"时"]];
            }
        }
    }else {
        
        if (compont == 0) {
            
            if (row == 0) {
                
                [dateArray addObject:self.endDayArray];
                [dateArray addObject:@[@"日"]];
                [dateArray addObject:self.endFirstHourTimeArray];
                [dateArray addObject:@[@"时"]];
            }else {
                
                [dateArray addObject:self.endDayArray];
                [dateArray addObject:@[@"日"]];
                [dateArray addObject:self.hourTimeArray];
                [dateArray addObject:@[@"时"]];
            }
        }
    }
    
    return dateArray;
}


/**
 获取时间数组(初始化)

 @param delayHourTime 当前时间往后延迟的小时数
 @param timeType 时间类型 1: 开始时间 , 2: 结束时间
 */
- (void)getTimeArrayWithDelayHourTime:(NSInteger)delayHourTime timeType:(NSInteger)timeType beginDay:(NSInteger)beginDay endDay:(NSInteger)endDay {
    
    for (NSInteger i = beginDay; i < endDay; i ++) { // 获取天数
        
        NSTimeInterval timeStamp = [self getOneDayTimeStampWithOneDayFromNow:i delayHourTime:delayHourTime];
        
        NSString *dateString = [self getOneDayWithFormatter:@"yyyy-MM-dd" timeStamp:timeStamp / 1000];
        if (timeType == 1) {
            
            [self.beginDateTimeArray addObject:dateString];
            [self.beginDayArray addObject:[self getOneDayWithFormatter:@"dd" timeStamp:timeStamp / 1000]];
        }else {
            
            [self.endDateTimeArray addObject:dateString];
            [self.endDayArray addObject:[self getOneDayWithFormatter:@"dd" timeStamp:timeStamp / 1000]];
        }
    }
    
    
    // 获取第一天的小时数组
    NSTimeInterval timeStamp = [self getOneDayTimeStampWithOneDayFromNow:beginDay delayHourTime:delayHourTime];
    if (timeType == 1) {
        
        for (NSInteger hourNumber = [[self getOneDayWithFormatter:@"HH" timeStamp:timeStamp / 1000] integerValue]; hourNumber <= 23; hourNumber ++) {
            
            if (hourNumber == 00) {
                
                [self.beginFirstHourTimeArray addObject:[NSString stringWithFormat:@"00"]];
            }else {
                
                [self.beginFirstHourTimeArray addObject:[NSString stringWithFormat:@"%.2ld" , (long)hourNumber]];
            }
        }
        
    }else {
        
        NSInteger hourNum = 0;
        if (self.beginTimeStamp > 0) { // 判断是否选择开始的预约时间
            
            NSTimeInterval endTimeStamp = self.beginTimeStamp + 1 * 60 * 60 * 1000;
            hourNum = [[self getOneDayWithFormatter:@"HH" timeStamp:endTimeStamp / 1000] integerValue];
        }else {
            
            hourNum = [[self getOneDayWithFormatter:@"HH" timeStamp:timeStamp / 1000] integerValue];
        }
        
        for (NSInteger hourNumber = hourNum; hourNumber <= 23; hourNumber ++) {
            
            if (hourNumber == 00) {
                
                [self.endFirstHourTimeArray addObject:[NSString stringWithFormat:@"00"]];
            }else {
                
                [self.endFirstHourTimeArray addObject:[NSString stringWithFormat:@"%.2ld" , (long)hourNumber]];
            }
        }
    }
    
    // 第二天(包含)以后的的小时数组
    for (NSInteger hourNumber = 0; hourNumber <= 23; hourNumber ++) {
        
        if (hourNumber == 00) {
            
            [self.hourTimeArray addObject:[NSString stringWithFormat:@"00"]];
        }else {
            
            [self.hourTimeArray addObject:[NSString stringWithFormat:@"%.2ld" , (long)hourNumber]];
        }
    }
}

/**
 清楚缓存
 */
- (void)clearCache {
    
    self.beginTimeStamp = -1.0;
    [self.beginFirstHourTimeArray removeAllObjects];
    [self.beginDayArray removeAllObjects];
    [self.beginDateTimeArray removeAllObjects];
    self.beginHourTimeString = @"";
    self.beginDateTimeString = @"";
    
    [self.hourTimeArray removeAllObjects];
    
    self.endTimeStamp = -1.0;
    [self.endFirstHourTimeArray removeAllObjects];
    [self.endDayArray removeAllObjects];
    [self.endDateTimeArray removeAllObjects];
    self.endHourTimeString = @"";
    self.endDateTimeString = @"";

    [self configureLisenToSingleModeVCUI];
}


/**
 清楚数组
 */
- (void)clearArray {
    
    [self.beginFirstHourTimeArray removeAllObjects];
    [self.beginDayArray removeAllObjects];
    [self.beginDateTimeArray removeAllObjects];
    
    [self.endFirstHourTimeArray removeAllObjects];
    [self.endDayArray removeAllObjects];
    [self.endDateTimeArray removeAllObjects];
    
    [self.hourTimeArray removeAllObjects];
}


/**
 从当前时间获取某一天的时间戳
 
 @param oneDayNumber 某一天
 @param delayHourTime 该天往后延迟的小时数 例如当前时间 2017-02-20 14:30:00 ,延迟一小时为2017-02-20 15:30:00
 @return 时间戳
 */
- (NSTimeInterval)getOneDayTimeStampWithOneDayFromNow:(NSInteger)oneDayNumber delayHourTime:(NSInteger)delayHourTime {
    
    NSDate *nowDate = [NSDate dateWithTimeIntervalSinceNow:(oneDayNumber * 24 * 60 * 60 + delayHourTime * 60 * 60)];
    NSTimeInterval dateTimeStamp = [nowDate timeIntervalSince1970] * 1000;
    
    return dateTimeStamp;
}


/**
 返回某一时间戳延迟N小时候的时间戳

 @param oneDayTimeStamp 某一天的时间戳
 @param delayHourTime 延迟的小时数
 */
- (NSTimeInterval)getOneDayTimeStampFromOneDayTimeStamp:(NSTimeInterval)oneDayTimeStamp delayHourTime:(NSInteger)delayHourTime {
    
    NSDate *nowDate = [NSDate dateWithTimeIntervalSince1970:oneDayTimeStamp + delayHourTime * 60 * 60];
    
    return [nowDate timeIntervalSince1970] * 1000;
}

#pragma mark -完成设置
- (IBAction)completeAction:(UIButton *)sender {
    

    
    if (self.remindType == 1 || self.remindType == 3) { // 如果是全部订单,预约单
        
        if ((self.endTimeStamp <= self.beginTimeStamp) && self.endTimeStamp > 0) { // 如果结束时间小于等于开始时间抛出提示语不在执行 , 并且结束的时间大于零(不为-1.0)代表结束时间设置了,如果小于等于0(为-1.0)代表没有设置结束时间
            CGFloat hiddenTime = 2.0;
            
                
            self.popView.layer.anchorPoint = CGPointMake(0.5, 0.5);
            self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
            dispatch_async(dispatch_get_main_queue(), ^{
                
                MBProgressHUD *mb = [MBProgressHUD showWithText:@"结束时间的选择范围必须晚于开始时间" onView:self.view hiddenDuration:hiddenTime];
                mb.userInteractionEnabled = NO;
            });

            [self performSelector:@selector(refreshPopViewUI) withObject:nil afterDelay:hiddenTime];

            return;
        }
    }
    
    NSMutableDictionary *timeDic = [NSMutableDictionary dictionary];
    [timeDic setValue:(self.beginTimeStamp > 0 ? [NSString stringWithFormat:@"%.f" , self.beginTimeStamp] : @"") forKey:@"appointTimeStart"];
    [timeDic setValue:(self.endTimeStamp > 0 ? [NSString stringWithFormat:@"%.f" , self.endTimeStamp] : @"") forKey:@"appointTimeEnd"];
    [self listeningModeSettingRequestWithRemindType:self.remindType timeDictionary:timeDic];
    
    self.popView.layer.anchorPoint = CGPointMake(0.0, 1.0);
    self.popView.frame = CGRectMake(30, 100, self.popView.frame.size.width, self.popView.frame.size.height);
    
    [UIView animateWithDuration:0.2 delay:0.0 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
        
        self.popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.01f, 0.01f);
    } completion:^(BOOL finished) {
        
        self.view.alpha = 0.0;
    }];
}

#pragma mark - 点击空白处的Action
- (IBAction)clickBlankPositionAction:(UITapGestureRecognizer *)sender {
    
    
}


#pragma mark - 弹出动画
- (void)presentViewAnimated:(BOOL)animated {
    
    if (animated) {
        
        self.popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f, 1.0f);
        self.view.alpha = 1.0;
        [self setAnimationAnchorPoint:CGPointMake(0.0, 1.0)];

        self.popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.01f, 0.01f);
        
        [UIView animateWithDuration:0.3 delay:0.0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
           
            self.popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f, 1.0f);
        } completion:^(BOOL finished) {
            
            
        }];
        
    }else {
        
        self.view.alpha = 1.0;
        self.popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0f, 1.0f);
    }

}

- (void)setAnimationAnchorPoint:(CGPoint)point
{
    CGRect originRect = self.popView.frame;
    self.popView.layer.anchorPoint = point;
    self.popView.frame = CGRectMake(30, 100, originRect.size.width, originRect.size.height);
    self.popView.layer.anchorPoint = point;
}

#pragma mark - TimeSelectorVCDelegate
- (void)timeSelectorVC:(TimeSelectorVC *)timeSelectorVC pickView:(UIPickerView *)pickView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    if (component == 2) {
        
        self.selectHourRow = row;
    }
    
    if (component == 0) {
        
        self.selectDayRow = row;
        
        if (self.timeSelectorType == 1) {
            
            if (self.selectHourRow > self.beginFirstHourTimeArray.count - 1) {
                
                if (row == 0) {
                    
                    self.selectHourRow = self.beginFirstHourTimeArray.count - 1;
                }
                
            }
        }else {
            
            if (self.selectHourRow > self.endFirstHourTimeArray.count - 1) {
                
                if (row == 0) {
                    
                    self.selectHourRow = self.endFirstHourTimeArray.count - 1;
                }
                
            }
        }

    }
    
    // 滚动的时候刷新数据源
    if (component == 0) {
        
        if (row == 0) {
            
            timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:component row:row];
            
        }else {
            
            timeSelectorVC.dataSource = [self getDatasourceWithTimeType:self.timeSelectorType compont:component row:row];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [pickView reloadAllComponents];
        });
    }
    
    // 时间转化
    if (self.timeSelectorType == 1) {
        
        
        if (component == 0) {
            
            self.beginDateTimeString = self.beginDateTimeArray[row]; // yyyy-MM-dd;
            if (row == 0) {
                
                self.beginHourTimeString = self.beginFirstHourTimeArray[self.selectHourRow];
            }else {
                
                self.beginHourTimeString = self.hourTimeArray[self.selectHourRow];
            }
        }else if (component == 2) {
            
            if (self.selectDayRow == 0) {
                
                self.beginHourTimeString = self.beginFirstHourTimeArray[row];
            }else {
                
                self.beginHourTimeString = self.hourTimeArray[row];
            }
        }
        
        NSString *timeString = [NSString stringWithFormat:@"%@ %@:00:00:000" , self.beginDateTimeString , self.beginHourTimeString]; // yyyy-MM-dd HH:mm:ss:SSS
        NSTimeInterval timeStamp = [self getOneDayTimeStampWithTimeString:timeString formatter:@"yyyy-MM-dd HH:mm:ss:SSS"] * 1000; // 转化到毫秒
        self.beginTimeStamp = timeStamp;
        

        
    }else {
        
        if (component == 0) {
            
            self.endDateTimeString = self.endDateTimeArray[row]; // yyyy-MM-dd;
            if (row == 0) {
                
                self.endHourTimeString = self.endFirstHourTimeArray[self.selectHourRow];
            }else {
                
                self.endHourTimeString = self.hourTimeArray[self.selectHourRow];
            }
        }else if (component == 2) {
            
            if (self.selectDayRow == 0) {
                
                self.endHourTimeString = self.endFirstHourTimeArray[row];
            }else {
                
                self.endHourTimeString = self.hourTimeArray[row];
            }
        }
        
        NSString *timeString = [NSString stringWithFormat:@"%@ %@:00:00:000" , self.endDateTimeString , self.endHourTimeString]; // yyyy-MM-dd HH:mm:ss:SSS
        NSTimeInterval timeStamp = [self getOneDayTimeStampWithTimeString:timeString formatter:@"yyyy-MM-dd HH:mm:ss:SSS"] * 1000;
        self.endTimeStamp = timeStamp;
    }
}

#pragma mark - 清除开始预约时间
- (IBAction)clearBeiginTime:(UIButton *)sender {
    
    [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_Begin];
    [self configureLisenToSingleModeVCUI];
}

#pragma mark - 清楚结束预约时间
- (IBAction)clearEndTime:(UIButton *)sender {
    
    [QXDataManager saveValue:@"-1" forKey:LisenToSingleModeAppointTime_End];
    [self configureLisenToSingleModeVCUI];
}



#pragma mark - 听单模式设置网络请求

/**
 设置听单模式

 @param remindType 听单模式 1：全部，2：实时 3：预约
 */
- (void)listeningModeSettingRequestWithRemindType:(NSInteger)remindType timeDictionary:(NSDictionary *)timeDictionary {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
       
        MBProgressHUD *mb = [MBProgressHUD showHUDAddedTo:self.view.superview animated:YES];
        mb.userInteractionEnabled = NO;
    });
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:@(remindType) forKey:@"remindType"];
    [parameters setValuesForKeysWithDictionary:timeDictionary];
    __weak typeof(self) weakSelf = self;
    [DLLApiManager listenModeSettingsWithParameters:parameters success:^(id data) {
        
        __strong typeof(self) strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [MBProgressHUD hideHUDForView:strongSelf.view.superview animated:NO];
            
            if (NetWork_Success) {
                
                IflyMSCManager *iflyMSCManager = [IflyMSCManager startSyntheticSpeechWithText:@"完成设置"];
                [iflyMSCManager.iFlySpeechSynthesizer setParameter:[NSString stringWithFormat:@"80"] forKey:[IFlySpeechConstant SPEED]];
            }
        });
        
        
    } failure:^(NSError *error) {
        
        __strong typeof(self) strongSelf = weakSelf;
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [MBProgressHUD hideHUDForView:strongSelf.view.superview animated:NO];
        });
    }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
